﻿using System.Windows;
using System.Windows.Data;

namespace Sinacor.Infra.UI.Controls.SmartClient.DataGrid
{
    public class DataGridTemplateColumn : Microsoft.Windows.Controls.DataGridTemplateColumn, IDataGridColumn
    {
        #region Construtores
        /// <summary>
        /// Construtor estático
        /// </summary>
        static DataGridTemplateColumn()
        {
            DataGridColumnManager.Initialize(typeof(DataGridTemplateColumn));
        }
        #endregion

        #region Name
        public static readonly DependencyProperty NameProperty = DataGridColumnManager.NameProperty.AddOwner(typeof(DataGridTemplateColumn));
        /// <summary>
        /// Nome da coluna
        /// </summary>
        public string Name
        {
            get { return (string)GetValue(NameProperty); }
            set { SetValue(NameProperty, value); }
        }
        #endregion

        #region DataGrid
        /// <summary>
        /// DataGrid para o qual a coluna pertence
        /// </summary>
        public SinacorDataGrid DataGrid
        {
            get { return (SinacorDataGrid)base.DataGridOwner; }
        }
        #endregion

        #region Binding
        private BindingBase _binding = null;
        /// <summary>
        /// Binding do valor a ser exportado para o Excel
        /// </summary>
        public BindingBase Binding
        {
            get
            {
                return _binding;
            }
            set
            {
                _binding = value;
            }
        }
        #endregion

        #region SortIndex
        public static readonly DependencyProperty SortIndexProperty = DataGridColumnManager.SortIndexProperty.AddOwner(typeof(DataGridTemplateColumn));
        /// <summary>
        /// Ordem que a coluna foi ordenada
        /// </summary>
        public int SortIndex
        {
            get { return (int)GetValue(SortIndexProperty); }
            protected set { SetValue(DataGridColumnManager.SortIndexKey, value); }
        }
        #endregion

        #region HorizontalCellAlignment
        public static readonly DependencyProperty HorizontalCellAlignmentProperty = DataGridColumnManager.HorizontalCellAlignmentProperty.AddOwner(typeof(DataGridTemplateColumn));
        /// <summary>
        /// Alinhamento horizontal do conteúdo da célula
        /// </summary>
        public HorizontalAlignment HorizontalCellAlignment
        {
            get { return (HorizontalAlignment)GetValue(HorizontalCellAlignmentProperty); }
            set { SetValue(HorizontalCellAlignmentProperty, value); }
        }
        #endregion

        #region VerticalCellAlignment
        public static readonly DependencyProperty VerticalCellAlignmentProperty = DataGridColumnManager.VerticalCellAlignmentProperty.AddOwner(typeof(DataGridTemplateColumn));
        /// <summary>
        /// Alinhamento vertical do conteúdo da célula
        /// </summary>
        public VerticalAlignment VerticalCellAlignment
        {
            get { return (VerticalAlignment)GetValue(VerticalCellAlignmentProperty); }
            set { SetValue(VerticalCellAlignmentProperty, value); }
        }
        #endregion

        #region CanUserChangeVisibility
        public static readonly DependencyProperty CanUserChangeVisibilityProperty = DataGridColumnManager.CanUserChangeVisibilityProperty.AddOwner(typeof(DataGridTemplateColumn));
        /// <summary>
        /// Indica se o usuário pode alterar a visibilidade da coluna
        /// </summary>
        public bool CanUserChangeVisibility
        {
            get { return (bool)GetValue(CanUserChangeVisibilityProperty); }
            set { SetValue(CanUserChangeVisibilityProperty, value); }
        }
        #endregion

        #region ClipboardContentBinding
        public override BindingBase ClipboardContentBinding
        {
            get
            {
                return base.ClipboardContentBinding ?? this.Binding;
            }
            set
            {
                base.ClipboardContentBinding = value;
            }
        }
        #endregion

        #region Excel

        #region CanUserExportExcel
        public static readonly DependencyProperty CanUserExportExcelProperty = DataGridColumnManager.CanUserExportExcelProperty.AddOwner(typeof(DataGridTemplateColumn));
        /// <summary>
        /// Indica se a coluna permite ser exportada para Excel
        /// </summary>
        public bool CanUserExportExcel
        {
            get { return (bool)GetValue(CanUserExportExcelProperty); }
            set { SetValue(CanUserExportExcelProperty, value); }
        }
        #endregion

        #region ExcelContentBinding
        private BindingBase _excelContentBinding = null;
        /// <summary>
        /// Binding do valor a ser exportado para o Excel
        /// </summary>
        public BindingBase ExcelContentBinding
        {
            get
            {
                return _excelContentBinding ?? this.Binding;
            }
            set
            {
                _excelContentBinding = value;
            }
        }
        #endregion

        #endregion

        #region PropertyChanged
        protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);
            DataGridColumnManager.PropertyChanged(this, e);
        }
        #endregion

		public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
		void IDataGridColumn.TriggerPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
		}
    }
}